-- stone_prop
-- create by panyl
-- 贤者之语
--     stone_prop(attrib, value,max)：第一个参数为prop的作用类别、第二个是属性值，第三个参数为上限
-- 记录在stone_prop下

return {
    apply = function(source, target, skillId, round, para, extra)
        local attrib = para[1];
        local value = para[2];
        local max = para[3];

        local stoneProp = target.dbase:query("stone_prop", {});

        local curValue = stoneProp[attrib] or 0;
        local v = math.min(curValue + value, max);

        stoneProp[attrib] = v;

        target.dbase:set("stone_prop", stoneProp);

        AttribM.setAllDirty(source, true);

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { arr[1], tonumber(arr[2]), tonumber(arr[3]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        local stoneProp = ME.user.dbase:query("stone_prop", {});
        local attack = stoneProp["attack"] or 0;
        local magic  = stoneProp["magic"] or 0;
        local max_hp = stoneProp["max_hp"] or 0;
        local max_mp = stoneProp["max_mp"] or 0;

        -- 增加属性
        desc = string.gsub(desc, "{addon}", tostring(para[2]));

        -- 已增加属性
        desc = string.gsub(desc, "{addon_attack}", tostring(attack));
        desc = string.gsub(desc, "{addon_magic}", tostring(magic));
        desc = string.gsub(desc, "{addon_max_hp}", tostring(max_hp));
        desc = string.gsub(desc, "{addon_max_mp}", tostring(max_mp));

        -- 上限值
        desc = string.gsub(desc, "{addon_limit}", tostring(para[3]));

        -- 属性名称
        desc = string.gsub(desc, "{attrib}", FieldsM.getFieldName(para[1]));

        return desc;
    end,
};
